package com.xiaotao.learn.algorithm.string;

public class AddString {
    public static void main(String[] args) {
        String s = new AddString().addStrings("11", "123");
        System.out.println(s);
    }
    public String addStrings(String num1, String num2) {
        StringBuilder sb = new StringBuilder();
        int i = num1.length() - 1, j = num2.length() - 1, t = 0;
        int sum = 0;
        while(i >= 0 || j >= 0 || t > 0) {
            sum = 0;
            if(i >= 0) sum += (num1.charAt(i) - '0');
            if(j >= 0) sum += (num2.charAt(j) - '0');
            sum += t;
            sb.append(sum%10);
            t = sum/10;
            i--;j--;
        }
        return sb.reverse().toString();
    }
}
